// index.js
// 获取应用实例
const app = getApp()

Page({
  data: {
    imgUrl: [{
        img: '/image/yiyan/blueBg.jpg'
      },
      {
        img: '/image/yiyan/starBg.jpg'
      }
    ],
    navData: [{
        text: '热门',
        img: '/image/iconfont/hot.png'
      },
      {
        text: '全部',
        // img:'/image/iconfont/all.png'
      },
      {
        text: '一言',
        // img:'/image/iconfont/book.png'
      },
      {
        text: ' 美图',
        // img:'/image/iconfont/image.png'
      },
      {
        text: '工具',
        // img:'/image/iconfont/tools.png'
      },
    ],
    all: [{
        idx: 1,
        img: '/image/tabIcon/erweima.png',
        text: '二维码生成'
      },
      // {
      //   idx: 2,
      //   img: '/image/tabIcon/dsp.png',
      //   text: '短视频去水印'
      // },
      {
        idx: 3,
        img: '/image/tabIcon/my.png',
        text: '随机一言'
      },
      {
        idx: 4,
        img: '/image/tabIcon/mh.png',
        text: '随机二次元动漫美图'
      },
      {
        idx: 5,
        img: '/image/tabIcon/by.png',
        text: '每日必应美图'
      },
      {
        idx: 6,
        img: '/image/tabIcon/by.png',
        text: '颜值买家秀'
      },
      {
        idx: 7,
        img: '/image/tabIcon/by.png',
        text: '热搜榜'
      },
      {
        idx: 8,
        img: '/image/tabIcon/sjlj.png',
        text: '历史上的今天'
      },
      {
        idx: 9,
        img: '/image/tabIcon/lanzy.png',
        text: '蓝奏云直链获取'
      },
      {
        idx: 10,
        img: '/image/tabIcon/guisudi.png',
        text: '手机号归属地查询'
      },
      {
        idx: 11,
        img: '/image/tabIcon/lj.png',
        text: '垃圾分类查询'
      },
      {
        idx: 12,
        img: '/image/tabIcon/tianqi.png',
        text: '城市天气预报'
      },
    ],
    // hot:[
    //   {text:'二维码类'},{text:'短视频去水印'},{text:'蓝奏云直链获取'},{text:'音频类'},{text:'实时汇率'}
    // ],
    // oneword:[
    //   {text:'随机一言句子'},
    //   {text:'历史上的今天'},
    // ],
    // pic:[
    //   {text:'随机二次元动漫美图'},
    //   {text:'每日必应美图'},
    //   {text:'海报生成'},
    // ],
    // tools:[
    //   {text:'网站类'},
    //   {text:'二维码类'},
    //   {text:'蓝奏云直链获取'},
    //   {text:'IP签名档'},
    //   {text:'手机号归属地查询'},
    //   {text:'垃圾分类查询'},
    //   {text:'城市天气预报'},
    //   {text:'随机颜色'},
    // ],
    nameIcon: [],
    currentTab: 0,
    navScrollLeft: 0,
    windowWidth: 280,
    userInfo: {},
    hasUserInfo: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
    canIUseGetUserProfile: false,
    canIUseOpenData: wx.canIUse('open-data.type.userAvatarUrl') && wx.canIUse('open-data.type.userNickName') // 如需尝试获取用户信息可改为false
  },
  // 事件处理函数
  onLoad() {
    if (wx.getUserProfile) {
      this.setData({
        canIUseGetUserProfile: true
      })
    }
  },
  getUserProfile(e) {
    // 推荐使用wx.getUserProfile获取用户信息，开发者每次通过该接口获取用户个人信息均需用户确认，开发者妥善保管用户快速填写的头像昵称，避免重复弹窗
    wx.getUserProfile({
      desc: '展示用户信息', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
      success: (res) => {
        console.log(res)
        this.setData({
          userInfo: res.userInfo,
          hasUserInfo: true
        })
      }
    })
  },
  // 切换导航
  switchNav(event) {
    var cur = event.currentTarget.dataset.current;
    // console.log(event);
    //每个tab选项宽度占1/5
    var singleNavWidth = this.data.windowWidth / 5;
    // console.log(singleNavWidth);
    //tab选项居中                            
    this.setData({
      navScrollLeft: (cur - 2) * singleNavWidth
    })
    if (this.data.currentTab == cur) {
      return false;
    } else {
      this.setData({
        currentTab: cur
      })
    }
  },
  switchTab(event) {
    var cur = event.detail.current;
    var singleNavWidth = this.data.windowWidth / 5;
    this.setData({
      currentTab: cur,
      navScrollLeft: (cur - 2) * singleNavWidth
    });
  },
  tapItem(e) {
    var idx = e.currentTarget.dataset.current;
    console.log(idx, 'idx');
    switch (idx) {
      case 0:
        wx.navigateTo({
          url: '/pages/qrcode/qrcode',
        })
        break;
      // case 1:
      //   wx.navigateTo({
      //     url: '/pages/shuiyin/shuiyin',
      //   })
      //   break;
      case 1:
        wx.navigateTo({
          url: '/pages/yiyan/yiyan',
        })
        break;
      case 2:
        wx.navigateTo({
          url: '/pages/anime/anime',
        })
        break;
      case 3:
        wx.navigateTo({
          url: '/pages/bing/bing',
        })
        break;
      case 4:
        wx.navigateTo({
          url: '/pages/taobaoXiu/taobaoXiu',
        })
        break;
      case 5:
        wx.navigateTo({
          url: '/pages/hot/hot',
        })
        break;
      case 6:
        wx.navigateTo({
          url: '/pages/today/today',
        })
        break;
      case 7:
        wx.navigateTo({
          url: '/pages/lanzou/lanzou',
        })
        break;
      default:
        NaN
        break;
    }
  }
})